﻿using BootstrapBlazor.Components;

namespace ApiLib.RCL.Components.AutoTable.Attributes;

/// <summary>
/// 表格
/// </summary>
public class TableAttribute : Attribute
{
    /// <summary>
    /// 名称
    /// </summary>
    public string Name { get; set; }
    /// <summary>
    /// 显示默认字段，没有配置列的显示时，默认显示
    /// </summary>
    public bool UseDefaultColumn { get; set; } = true;

    /// <summary>
    /// 运行新增,默认true
    /// </summary>
    public bool CanAdd { get; set; } = true;

    /// <summary>
    /// 运行编辑,默认true
    /// </summary>
    public bool CanEdit { get; set; } = true;

    /// <summary>
    /// 允许删除,默认true
    /// </summary>
    public bool CanDelete { get; set; } = true;
    /// <summary>
    /// 允许上传,默认false
    /// </summary>
    public bool CanImport { get; set; } = false;
    /// <summary>
    /// 允许导出,默认false
    /// </summary>
    public bool CanExport { get; set; } = false;
    /// <summary>
    /// 弹窗大小
    /// </summary>
    public Size DialogSize { get; set; } = Size.Medium;
    /// <summary>
    /// 按钮样式
    /// </summary>
    public bool IsOutline { get; set; } = false;
    /// <summary>
    /// 链接按钮，默认true
    /// </summary>
    public bool IsLinkButton { get; set; } = true;
    /// <summary>
    /// 显示行号，默认false
    /// </summary>
    public bool ShowLineNo { get; set; } = false;
    
    /// <summary>
    /// 通知样式，默认为Message，设置为Swal时，使用Swal通知
    /// </summary>
    public bool IsSwalNotify { get; set; } = false;
    public int[] PageItemsSource { get; set; } = [10,20,30];

    public TableAttribute()
    {
    }

    public TableAttribute(string name)
    {
        Name = name;
    }

    /// <summary>
    /// 获取分页选项
    /// </summary>
    /// <returns></returns>
    public List<SelectedItem> GetPageSelectedItems()
    {
        return PageItemsSource.Select(item => new SelectedItem(item.ToString(), $"{item}条/页")).ToList();
    }
}